 /*
 * @description: 店铺数据/查看总销量弹窗
 * @Author: along
 * @Date: 2021-05-24
 * @Last Modified by: along
 * @Last Modified time: 2021-05-27
 */
<template>
    <el-dialog
        title="总销量"
        :visible.sync="dialogVisible"
        width="596px"
        :close-on-click-modal="false"
        class="__model"
    >
        <div class="__table">
            <el-table
                :data="tableData"
                height="100%"
                style="width: 100%"
                class="data-table"
            >
                <el-table-column
                    type="index"
                    label="排名"
                    width="80"
                    align="center"
                />
                <el-table-column
                    prop="goods_title"
                    label="商品名称"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="left"
                />
                <el-table-column
                    prop="status"
                    label="商品状态"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="left"
                >
                    <template slot-scope="scope">
                        <p :style="{color: 'rgba(51, 51, 51, 1)'}">
                            {{ scope.row.status | filterSattus }}
                        </p>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="goods_sale_count"
                    label="销量"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="left"
                />
            </el-table>
        </div>
        <!-- /分页 -->
        <div class="pagination-wrapper clearfixNew">
            <el-pagination
                layout="total, prev, pager, next, jumper"
                background
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>
    </el-dialog>
</template>

<script>
export default {
    name: 'CheckShopSale',
    data () {
        return {
            dialogVisible: false,
            tableData: [],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },

        };
    },
    filters: {
        filterSattus (val) {
            if(val === 0) return '已下架';
            if(val === -1) return '已删除';
            if(val === 1) return '已上架';
        }
    },
    methods: {
        /**
         * @description 显示弹窗
         */
        show (row) {
            this.shop_no = row.shop_no;
            this.getTableData(1);
            this.dialogVisible = true;
        },

        /**
         * @description 关闭弹窗
         */
        close () {
            this.dialogVisible = false;
        },

        /**
         * @description 获取表格数据
         */
        getTableData(page) {
            this.$post('/student/statistic_shop%5Cget_shop_goods_sales_ranking_list', {
                page_id: page || this.page.now_page,
                shop_no: this.shop_no
            }, resp => {
                if (resp.code === 1) {
                    this.tableData = resp.data.list;
                    this.page = {
                        ...resp.data.page
                    };
                } else {
                    this.$notify({
                        title: '失败',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
.__table {
    width: 100%;
    max-height: 424px;
    overflow: hidden;
    overflow-y: auto;
    box-sizing: border-box;
    border-left: 1px solid #EBEEF5;
    border-right: 1px solid #EBEEF5;
}
.pagination-wrapper {
    padding: 0px 24px;
    border: 1px solid #EBEEF5;
    display: flex;
    align-items: center;
    height: 56px;
    border-top: none;
    justify-content: flex-end;
    overflow: hidden;
    .el-pagination {
        float: right;
        padding: 0;
        background-color: transparent;
    }
}
</style>